<?php

class Display
{
	
	public static function transliterate($text, $toLowCase = false)
	{
		$matrix=array(
			"й"=>"i","ц"=>"c","у"=>"u","к"=>"k","е"=>"e","н"=>"n",
			"г"=>"g","ш"=>"sh","щ"=>"shch","з"=>"z","х"=>"h","ъ"=>"",
			"ф"=>"f","ы"=>"y","в"=>"v","а"=>"a","п"=>"p","р"=>"r",
			"о"=>"o","л"=>"l","д"=>"d","ж"=>"zh","э"=>"e","ё"=>"e",
			"я"=>"ya","ч"=>"ch","с"=>"s","м"=>"m","и"=>"i","т"=>"t",
			"ь"=>"","б"=>"b","ю"=>"yu",
			"Й"=>"I","Ц"=>"C","У"=>"U","К"=>"K","Е"=>"E","Н"=>"N",
			"Г"=>"G","Ш"=>"SH","Щ"=>"SHCH","З"=>"Z","Х"=>"X","Ъ"=>"",
			"Ф"=>"F","Ы"=>"Y","В"=>"V","А"=>"A","П"=>"P","Р"=>"R",
			"О"=>"O","Л"=>"L","Д"=>"D","Ж"=>"ZH","Э"=>"E","Ё"=>"E",
			"Я"=>"YA","Ч"=>"CH","С"=>"S","М"=>"M","И"=>"I","Т"=>"T",
			"Ь"=>"","Б"=>"B","Ю"=>"YU",
			"«"=>"","»"=>""," "=>"-",
			"\""=>"", "\."=>"", "–"=>"-", "\,"=>"", "\("=>"", "\)"=>"",
			"\?"=>"", "\!"=>"", "\:"=>"",
			'#' => '', '№' => '',' - '=>'-', '/'=>'-', '  '=>'-',
		);
		
		// Enforce the maximum component length
		$maxlength = 100;                                  
		$text = implode(array_slice(explode('<br>',wordwrap(trim(strip_tags(html_entity_decode($text))),$maxlength,'<br>',false)),0,1));
		//$text = substr(, 0, $maxlength); 

		foreach($matrix as $from => $to)
		{
			$text = mb_eregi_replace($from,$to,$text); 
		}

		if ($toLowCase) 
		{
		   $text = strtolower($text);
		}  

		return $text;
	}
	
	
	public static function truncateText($text, $length = 10, $add = '')
	{
		$dots = "...";
		$length -= mb_strlen($dots);
		if($length > 0)
		{
			$text = strip_tags($text);
			$text = str_replace(array("\r", "\n"), '', $text);

			$lenBefore = mb_strlen($text);
			if($length)
			{
				$text = mb_substr($text, 0, $length);
				if(mb_strlen($text) != $lenBefore)
				{
					$text .= $dots.$add;
				}
			}
		}

		return $text;
	}
	
	
	public static function listYears($start=1900, $end=null)
	{
		$end = $end ? $end : date("Y");
		$data = array();
		
		for ($i=$end; $i>=$start; $i--)
		{
			$data[$i] = $i;
		}
		
		return $data;
	}
}

?>
